package repository

import (
	"shop/src/global"
	"shop/src/model"
	"xorm.io/xorm"
)

type OrderRepository struct {
	engine *xorm.Engine
}

func NewOrderRepository(engine *xorm.Engine) *OrderRepository {
	return &OrderRepository{engine: engine}
}

func (r *OrderRepository) Create(order *model.Order) (int64, error) {
	order.Id = getOrderId()
	_, err := r.engine.InsertOne(order)
	if err != nil {
		return 0, err
	}
	return 0, nil
}

func getOrderId() int64 {
	return 0
}

func (r *OrderRepository) Delete(id int64) error {
	_, err := r.engine.ID(id).Delete()
	if err != nil {
		return err
	}
	return nil
}

func InsertOrders(orders []model.Order) error {
	_, err := global.Engine.Insert(orders)
	if err != nil {
		return err
	}
	return nil
}
